package com.xzc.controller;

import com.xzc.common.ResultBean;
import com.xzc.common.Rule;
import com.xzc.entity.Box;
import com.xzc.service.BoxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.*;

@RestController
@RequestMapping(value = "/box")
public class BoxController {

@Autowired
private BoxService boxService;



    @PostMapping("/get")
    public ResultBean getUserList(@RequestParam String orderId) {
        return new ResultBean(boxService.getOrderBox(orderId));
    }

    @PostMapping("split")
    public ResultBean splitBox(@RequestParam String orderId,
                               @RequestParam int boxId,
                               @RequestParam int part) {

        String msg = boxService.split(orderId, boxId, part);
        if (msg == null){
            return new ResultBean();
        }else {
            return new ResultBean().setError(msg);
        }
    }

    @PostMapping("merge")
    public ResultBean mergeBox(@RequestParam String orderId,
                               @RequestParam String boxIds) {

        List<String> boxIdList = Arrays.asList(boxIds.split(","));
        String msg = boxService.merge(orderId, boxIdList);
        if (msg == null){
            return new ResultBean();
        }else {
            return new ResultBean().setError(msg);
        }
    }


    @PostMapping("increase")
    public ResultBean increase(@RequestParam String orderId,
                               @RequestParam String nums) {
        String msg = boxService.increase(orderId,Integer.parseInt(nums));
        if (msg == null){
            return new ResultBean();
        }else {
            return new ResultBean().setError(msg);
        }
    }
}